/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/03/22
\**********************/
#ifndef __SD_LUAMGR_H__
#define __SD_LUAMGR_H__
#pragma once

#include <spdui/spdui.h>
#include <LuaPlus.h>
using namespace LuaPlus;

namespace DuiLib {

class SDWindow;
class CControlUI;

class SDLuaMgr
{
public:
    SDLuaMgr();
    ~SDLuaMgr();
public:
    void Init(LuaState* luastate = nullptr);
    void Quit();
    LuaObject AddObj(const char* key, void* data);
    void RemoveObj(void* data);
    bool DoFile(const char* file);
    LuaState* GetState() const;
    
    //SDLuaScript::
    virtual void* HandleMessage(SDWindow* wnd, SPDUI_MSG msg, void* data1 = 0, void* data2 = 0);
protected:
    //for return void
    void* DoEventVoid(void* key, LPCSTR name, void* data1 = 0, void* data2 = 0);
    //for return int
    void* DoEventInt(void* key, LPCSTR name, void* data1 = 0, void* data2 = 0);
    //for return cobj
    void* DoEventCObj(void* key, LPCSTR name, void* data1 = 0, void* data2 = 0);
    //for notify
    void* DoEventNotify(SDWindow* wnd, void* key, LPCSTR name, void* data1, void* data2);
protected:
    void Register();
    void UnRegister();
protected:
    bool m_bCreatedLua;
    LuaState* m_lua;
};

}
#endif //__SD_LUAMGR_H__
